// Student类
class Student {
    private String name;
    private int age;
    private String gender;
    private String major;
    private double gpa;

    public Student(String name, int age, String gender, String major, double gpa) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.major = major;
        this.gpa = gpa;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        this.gender = "Unknown";
        this.major = "Undeclared";
        this.gpa = 0.0;
    }

    public void study() {
        System.out.println(name + " is studying.");
    }

    public void takeExam() {
        System.out.println(name + " is taking an exam.");
    }

    public void displayInfo() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Gender: " + gender);
        System.out.println("Major: " + major);
        System.out.println("GPA: " + gpa);
    }
}

// Course类
class Course {
    private String name;
    private int credits;
    private String instructor;
    private int maxStudents;
    private int enrolledStudents;

    public Course(String name, int credits, String instructor, int maxStudents) {
        this.name = name;
        this.credits = credits;
        this.instructor = instructor;
        this.maxStudents = maxStudents;
        this.enrolledStudents = 0;
    }

    public void enrollStudent() {
        if (enrolledStudents < maxStudents) {
            enrolledStudents++;
            System.out.println("Student enrolled in " + name + ".");
        } else {
            System.out.println("Course is full. Cannot enroll more students.");
        }
    }

    public void dropStudent() {
        if (enrolledStudents > 0){
            enrolledStudents--;
            System.out.println("Student dropped from " + name + ".");
        } else {
            System.out.println("No students enrolled in the course.");
        }
    }

    public void displayInfo() {
        System.out.println("Course: " + name);
        System.out.println("Credits: " + credits);
        System.out.println("Instructor: " + instructor);
        System.out.println("Max Students: " + maxStudents);
        System.out.println("Enrolled Students: " + enrolledStudents);
    }
}

// 主函数中的调用示例
public class Main {
    public static void main(String[] args) {
        Student student1 = new Student("John", 20, "Male", "Computer Science", 3.5);
        Student student2 = new Student("Emily", 21, "Female", "Mathematics", 3.8);

        Course course1 = new Course("Java Programming", 3, "Professor Smith", 30);
        Course course2 = new Course("Data Structures", 4, "Professor Johnson", 25);

        student1.study();
        student2.takeExam();
        student1.displayInfo();

        course1.enrollStudent();
        course1.enrollStudent();
        course1.dropStudent();
        course1.displayInfo();

        course2.enrollStudent();
        course2.enrollStudent();
        course2.enrollStudent();
        course2.displayInfo();
    }
}